package hypergraph;

import java.util.LinkedList;
import java.util.List;

public class Node {
	private String			name;
	private HyperEdge		previous;
	private List<HyperEdge> adj;
	private boolean 		minPathMark;
	
	public Node (String name) {
		if (name == null) {
			throw new NullPointerException("null node name");
		}
		
		this.name = name;
		this.previous = null;
		this.adj = new LinkedList<HyperEdge> ();
	}
	
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public HyperEdge getPrevious() {
		return this.previous;
	}

	public void setPrevious(HyperEdge previous) {
		this.previous = previous;
	}

	public boolean add (HyperEdge h) {
		if (h == null) {
			throw new NullPointerException("null hyperedge");
		}
		
		return this.adj.add(h);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Node))
			return false;
		Node other = (Node) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	public List<HyperEdge> getAdj() {
		return adj;
	}


	public void setAdj(List<HyperEdge> adj) {
		this.adj = adj;
	}


	public boolean isMinPathMark() {
		return minPathMark;
	}


	public void setMinPathMark(boolean minPathMark) {
		this.minPathMark = minPathMark;
	}


	@Override
	public String toString() {
		return this.name; 
	}
	
	public String toDotString() {
		if (this.minPathMark == true) {
			return this.name + " [label=\"" + this.name + "\", style=bold, color=red];";
		} else {
			return this.name + " [label=\"" + this.name + "\", style=dashed, color=black];";
		}
	}
	
	public void clearForRevert(){
		
		adj=new LinkedList<HyperEdge>();
		minPathMark = false;
		previous = null;
	}
}